﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Team4Mock.DAO
{
    public class Provider
    {
        //@"Data Source=HEINIKEN-PC;Initial Catalog=Mock3Team;Persist Security Info=True;User ID=sa;Password=haibakhongsau";
        
        //Appdata
        //@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MockDatabase.mdf;Integrated Security=True;User Instance=True";
        public static string con = @"Data Source=HEINIKEN-PC;Initial Catalog=Mock3Team;Persist Security Info=True;User ID=sa;Password=haibakhongsau";
        public static SqlConnection Connection;
        public SqlConnection Connect()
        {
            Connection = new SqlConnection(con);
            if (Connection.State == ConnectionState.Closed)
                Connection.Open();
            return Connection;
        }
        public void CloseConnect()
        {
            if (Connection.State == ConnectionState.Open)
                Connection.Close();
            if (Connection.State == ConnectionState.Broken)
                Connection.Close();
            if (Connection.State == ConnectionState.Connecting)
                Connection.Close();
            if (Connection.State == ConnectionState.Executing)
                Connection.Close();
            if (Connection.State == ConnectionState.Fetching)
                Connection.Close();
            Connection.Dispose();
        }
    }
}